﻿#include<iostream>
#include<map>


class myCompare
{
public:
	bool operator()(int v1, int v2) const
	{
		return v1 > v2;
	}
};

void printMap(std::map<int, int, myCompare>& m)
{
	for (std::map<int, int, myCompare>::iterator it = m.begin(); it != m.end(); ++it)
	{
		std::cout << "key = " << it->first << "  value = " << (*it).second << '\n';
	}
	std::cout << '\n';
}


void test01()
{
	std::map<int, int> m1;

	m1.insert(std::pair<int, int>(6, 60));
	m1.insert(std::make_pair(2, 20));
	m1.insert(std::pair<int, int>(4, 40));
	m1.insert(std::make_pair(1, 10));
	m1.insert(std::pair<int, int>(3, 30));
	m1.insert(std::make_pair(5, 50));

	std::cout << "升序" << '\n';
	for (std::map<int, int>::iterator it = m1.begin(); it != m1.end(); ++it)
	{
		std::cout << "key = " << it->first << "  value = " << (*it).second << '\n';
	}
	std::cout << '\n';

	std::cout << "降序" << '\n';
	std::map<int, int, myCompare> m2;

	m2.insert(std::pair<int, int>(6, 60));
	m2.insert(std::make_pair(2, 20));
	m2.insert(std::pair<int, int>(4, 40));
	m2.insert(std::make_pair(1, 10));
	m2.insert(std::pair<int, int>(3, 30));
	m2.insert(std::make_pair(5, 50));

	printMap(m2);
}

int main()
{
	test01();
	
	return 0;
}